<?php
require_once ($INCLUDE_PATH . "./include/WebService2Db.php");
class EmailModel {
	//public $db_name; //"_email_number"
	public $db_name="";
    public function saveEmailInfo($s) {
        //$s1 = 'id';
        //$s2 = "'".$s['id']."'";
        foreach ($s as $key => $ss){
            if($key != 'id')
            {
                $s1 .= ",".$key;
                $s2 .= ",'".$ss."'";
            }
        }
		$s1 = substr($s1,1);
		$s2 = substr($s2,1);
        $DB=new DB_MYSQL;
        $sql="insert into `".PRE.$this->db_name."`(".$s1.")" ."VALUES(".$s2.")";

        //  $sql="SELECT *  FROM `hh_user` WHERE `account` = '".$username."' AND `password` = '".$password."'";
        $query = $DB->insert($sql,DB);
        //  echo $DB->insert_id;
        return $DB->insert_id;
    }
     public function editEmailInfo($id,$s) {

        foreach ($s as $key => $ss) {
           
            if($key != "account") {
                
                $s1 .= ",".$key."='".$ss."'";
              
            }else{
                 $s1 .= $key."='".$ss."'";
            }
        }
		$s1 = substr($s1,1);
        $DB=new DB_MYSQL;
        $sql="update  `".PRE.$this->db_name."` set ".$s1.
			" where id=".$id;
      //  $sql="insert into `".PRE."_user`(".$s1.")" ."VALUES(".$s2.")";

        //  $sql="SELECT *  FROM `hh_user` WHERE `account` = '".$username."' AND `password` = '".$password."'";
        $query = $DB->update($sql,DB);
       //  echo $affected_rows;
        return $DB->affected_rows;
    }
	public function getEmailInfo($id)
	{
		$DB=new DB_MYSQL;
        $DB->connect();
        $sql="SELECT *  FROM `".PRE.$this->db_name."` WHERE `id` = ".$id."";
        $query = $DB->query_first($sql);
        return $query;
	}
	
    public function getListCount() {
        //$where = " where state = 1";
        $DB=new DB_MYSQL;
        $table=PRE.$this->db_name;
        $sum=$DB->count_records($table,"id",$where,DB);
        return $sum;

    // echo $sum;
    }
    public function getList($page,$liststart,$pageSize) {
        $DB=new DB_MYSQL;
        $sql="SELECT *  FROM `".PRE.$this->db_name."`  LIMIT ".$liststart.",".$pageSize;
        $query = $DB->fetch_array($sql,DB);
        return $query;

    }
    public function delUser($id) {
        $DB=new DB_MYSQL;
        $sql = " delete from ".PRE.$this->db_name." where id=".$id;
        $query = $DB->delete($sql, PRE);
    }

}
?>
